<template>
  <div>
<div style="display: flex;justify-content: space-between">
  <!--    tree-->
  <el-card style="width: 215px;height: 855px">
<template #default="{row}">
  {{row}}
  <el-tree :data="data"
           icon-class="el-icon-circle-plus "
           style="color: skyblue"
           :props="defaultProps"
           @node-click="handleNodeClick"
  ></el-tree>
</template>
  </el-card>
<div>
  <!--机构信息-->
  <el-card style="width: 1000px;height: 500px;">
    <div>机构信息</div>
    <el-form :model="form" style="display: flex;justify-content: space-around" :disabled="disabled">
      <el-form-item label="机构编号">
        <el-input v-model="form.parentId" style="width: 185px;height: 40px"/>
      </el-form-item>
      <el-form-item label="机构名称">
        <el-input v-model="form.name" style="width: 185px;height: 40px"/>
      </el-form-item>
      <el-form-item label="机构类型">
        <el-input style="width: 185px;height: 40px"/>
      </el-form-item>
    </el-form>

    <!--    下拉框select      1111-->

    <el-select v-model="form.province.id" clearable placeholder="请选择省" :disabled="disabled">
      <el-option
        v-for="item in provinceList"
        :key="item.id"
        :label="item.name"
        :value="item.id">
      </el-option>
    </el-select>
    <!--下拉框              22222222222-->
    <el-select v-model="form.city.id" clearable placeholder="请选择市" :disabled="disabled">
      <el-option
        v-for="item in cityList"
        :key="item.id"
        :label="item.name"
        :value="item.id">
      </el-option>
    </el-select>
    <!--    下拉框         333333333333-->
    <el-select v-model="form.county.id" clearable placeholder="请选择县/区" :disabled="disabled">
      <el-option
        v-for="item in countyList"
        :key="item.id"
        :label="item.name"
        :value="item.id">
      </el-option>
    </el-select>
    <!--    继续form表单-->
    <el-form style="display: flex;justify-content: space-around" :disabled="disabled">
      <el-form-item label="详细地址">
        <el-input v-model="form.address" style="width: 185px;height: 40px"/>
      </el-form-item>
      <el-form-item label="经度">
        <el-input v-model="form.longitude" style="width: 185px;height: 40px"/>
      </el-form-item>
      <el-form-item label="纬度">
        <el-input v-model="form.latitude" style="width: 185px;height: 40px"/>
      </el-form-item>
    </el-form>
    <!--    继续form表单-->
    <el-form style="display: flex;justify-content: space-around" :disabled="disabled">
      <el-form-item label="机构负责人">
        <el-input v-model="form.managerName" style="width: 185px;height: 40px"/>
      </el-form-item>
      <el-form-item label="机构电话">
        <el-input v-model="form.phone" style="width: 185px;height: 40px"/>
      </el-form-item>
    </el-form>
    <!--    保存按钮-->
    <el-row type="flex" justify="center">
      <el-button type="danger" size="large" @click="subnit" v-if="show1">编辑</el-button>
      <el-button type="danger" size="large"  v-if="show">保存</el-button>
    </el-row>
  </el-card>
  <!--  员工薪资-->
  <el-card>
    <div>员工信息</div>
    <el-table :data="tandata">
      <el-table-column  label="序号" type="index" />
      <el-table-column label="员工编号" prop="userId"/>
      <el-table-column label="员工姓名" prop="name"/>
      <el-table-column label="手机号" prop="mobile"/>
      <el-table-column label="所属机构" prop="agency.name"/>
      <el-table-column label="系统账户" prop="account"/>
      <el-table-column label="系统角色" prop="roleNames"/>
      <el-table-column label="账户状态" prop="status">
        <template #default="{row}">
          <el-row type="flex" align="middle">
            <el-col v-if="row.status===1"> <div style="width: 10px;height: 10px;border-radius: 50%;background-color: aquamarine "/></el-col>
            <el-col>正常</el-col>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</div>
</div>
  </div>
</template>

<script>

import { getAreasApi, getAreasByIdAPI, getBusinessHallApi, GetListApi, getuserApi } from '@/api/instiution'

export default {

  components: {},
  props: {},
  data () {
    // 这里存放数据
    return {
      disabled: true,
      show: false,
      show1: false,
      data: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      options: [],
      value: '',
      id: '', // 用于获取机构详情id
      // form对应数据
      form: {
        parentId: '',
        name: '',
        province: {
          id: '',
          lat: '',
          lng: '',
          mutiPoints: null,
          name: ''
        },

        city: {
          id: '',
          lat: '',
          lng: '',
          mutiPoints: null,
          name: ''
        },

        county: {
          id: '',
          latitude: '',
          longitude: '',
          managerName: '',
          name: ''
        },
        address: '',
        longitude: '',
        latitude: '',
        managerName: '',
        phone: ''
      },
      tandata: [],
      parentId: '', // 调接口需要的
      page: {
        page: 1,
        pageSize: 5
      },
      provinceList: [],
      cityList: [],
      countyList: []

    }
  },
  // 计算属性 类似于 data 概念
  created () {
    this.getList()
  },
  methods: {
    // 点击tree之后的回调
    handleNodeClick (data) {
      console.log(data)
      this.id = data.id
      console.log(this.id)
      this.gethall(this.id)// 调用接口并且传递参数
      this.getarea()
      this.getUser()
      this.show1 = true
    },
    // 获取树形接口
    async getList () {
      const res = await GetListApi()
      this.data = JSON.parse(res.data)
      console.log(this.data)
    },
    // 获取机构详情
    async gethall (id) {
      const res = await getBusinessHallApi(id)
      console.log(res)
      this.form = res.data
      // console.log(this.form)
      // console.log(res.data.province.id)
      this.parentId = res.data.province.id
      // console.log(this.parentId)
      this.options = [res.data]
      console.log(this.options)
      this.value = this.options.name
      this.value = undefined
    },
    // 获取地址信息
    async getarea () {
      // const res = await getAreasApi()
      // this.options = res.data
      const res = await Promise.all([
        getAreasApi(),
        getAreasByIdAPI(this.form.province.id),
        getAreasByIdAPI(this.form.city.id)
      ])
      console.log(res)
      const res1 = res[0]
      this.provinceList = res1.data
      const res2 = res[1]
      this.cityList = res2.data
      const res3 = res[2]
      this.countyList = res3.data
      console.log(this.provinceList)
      console.log(this.cityList)
      console.log(this.countyList)
    },
    // 员工信息
    async getUser () {
      const res = await getuserApi({
        page: this.page.page,
        pageSize: this.page.pageSize
      })
      this.tandata = res.data.items
      console.log(this.tandata)
    },
    // 点击编辑
    subnit () {
      this.show = true
      this.show1 = false
      this.disabled = false
    }
  }

}

</script>

<style scoped>
</style>
